<template>
  <a-modal
    title="物料选择"
    class="normal-modal"
    :visible="visible"
    :centered="true"
    @ok="handleOk"
    @cancel="visible = false"
  >
    <!--        <searchData :searchData="searchArr" @search="search"></searchData>-->
    <b-table
      ref="table"
      :request="loadData"
      :select-config="{use:true,type:'radio',rowKey:'id'}"
      :columns="columns"
      @row-click="rowClick"
    >
      <span
        slot="num"
        slot-scope="text, record, index"
      >{{ index + 1 }}</span>
    </b-table>
  </a-modal>
</template>
<script>
import { materialsMainList } from '@/api/material/procurement/sign'

/*
* 1419 【测试】法务-合同管理-物资合同评审：物资合同评审选择物料，只能选择会签编码带过来的物料

*
* */
export default {
	name:'a'+Date.now(),
    name: 'DetailDialog',
    props: {
        urlFun: {
            type: Function
        },
        params: {
            type: Object,
            default() {
                return {}
            }
        },
        otherData: {
            type: Object,
            default() {
                return {}
            }
        }
    },
    data: function() {
        return {
            visible: false,
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' },
                    width: 70
                },
                {
                    title: '物料名称',
                    dataIndex: 'materialName',
                    width: 120
                },
                {
                    title: '物料编码',
                    dataIndex: 'materialCode',
                    width: 140
                },
                {
                    title: '规格型号',
                    dataIndex: 'materialModel'
                },
                {
                    title: '单位',
                    dataIndex: 'unit',
                    width: 100
                },
            ],
            searchArr: [
                {
                    name: '物料名称',
                    value: 'name',
                    type: 'input'
                },
                {
                    name: '物料编码',
                    value: 'code',
                    type: 'input'
                },
                {
                    name: '物资目录名称',
                    value: 'catalogName',
                    type: 'input'
                },
                {
                    name: '物资目录编码',
                    value: 'catalogCode',
                    type: 'input'
                }
            ],
            selectRow: null,
            queryParams: {},
            loadData: params => {
                let searchData = { commonStatus: 1 }
                searchData = Object.assign(searchData, params, this.otherData, this.params, this.queryParams)
                return materialsMainList(searchData)
            }
        }
    },
    methods: {
        open: function() {
            this.visible = true
            this.search()
        },
        rowClick(e, row) {
            this.selectRow = row
        },
        handleOk: function() {
            console.log(this.selectRow)
            if (this.selectRow === null) {
                // if (!this.selectRow) {
                this.$message.error('请选择基础数据')
                return
            }
            this.visible = false
            this.$emit('createList', this.selectRow)
        },
        search(val) {
            this.queryParams = val || {}
            this.$refs.table && this.$refs.table.getData(null, true)
        }
    }
}
</script>
